package com.jzsk.variable.center.common.utils.redis;

import cn.hutool.core.util.StrUtil;
import cn.hutool.crypto.digest.MD5;

/**
 * @author jiangli
 */
public class JedisConfig {

    private String host;

    private Integer port = 6379;

    private String password;

    private int database = 0;

    private int timeout = 5000;

    private int maxTotal = 2000;

    private int maxIdle = 50;

    private int maxWaitMillis = 5000;

    private boolean testOnBorrow = false;

    public JedisConfig() {
    }

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public int getDatabase() {
        return database;
    }

    public void setDatabase(int database) {
        this.database = database;
    }

    public int getTimeout() {
        return timeout;
    }

    public void setTimeout(int timeout) {
        this.timeout = timeout;
    }

    public int getMaxTotal() {
        return maxTotal;
    }

    public void setMaxTotal(int maxTotal) {
        this.maxTotal = maxTotal;
    }

    public int getMaxIdle() {
        return maxIdle;
    }

    public void setMaxIdle(int maxIdle) {
        this.maxIdle = maxIdle;
    }

    public int getMaxWaitMillis() {
        return maxWaitMillis;
    }

    public void setMaxWaitMillis(int maxWaitMillis) {
        this.maxWaitMillis = maxWaitMillis;
    }

    public boolean isTestOnBorrow() {
        return testOnBorrow;
    }

    public void setTestOnBorrow(boolean testOnBorrow) {
        this.testOnBorrow = testOnBorrow;
    }

    public String key() {
        if (StrUtil.isEmpty(host)) {
            throw new RuntimeException("redis host is empty");
        }
        return MD5.create().digestHex(host + ":" + port + ":" + database);
    }

}
